<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        字典
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
</head>
<style>

</style>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>字典标题</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="title" v-model="dataDictionary.title"
                               lay-verify="required" placeholder="字典标题" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>字典标签</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="label"
                               v-model="dataDictionary.label"
                               lay-verify="required" placeholder="字典标签" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>类型</label>
                    <div class="layui-input-inline">
                        <select lay-verify="required" name="type">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>
                <div class=" layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>序号</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  min="0" type="number" name="serialNumber"
                               v-model="dataDictionary.serialNumber"
                               placeholder="序号" class="layui-input">
                    </div>
                </div>

                <div class=" layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>字典值</label>
                    <div class="layui-input-block">
                        <textarea name="dataValue" placeholder="请输入内容" v-model="dataDictionary.dataValue"
                                  lay-verify="required" class="layui-textarea"></textarea>
                    </div>
                </div>


                <div class=" layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>字典备注</label>
                    <div class="layui-input-block">
                        <textarea name="dataRemark" placeholder="请输入内容" v-model="dataDictionary.dataRemark"
                                  class="layui-textarea"></textarea>
                    </div>
                </div>


                <div style="text-align: center" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                        保存
                    </button>
                </div>
                <div style="height:100px;"></div>
            </div>

        </div>

    </form>
</div>
<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../js/pub.js"></script>
<script src="../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../js/vue.min.js" charset="utf-8"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var recordId = getQueryVariable("recordId");

    layui.use(['laydate', 'form', 'layer'],
        function () {
            var form = layui.form;
            var layer = layui.layer;

            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    let form = data.field;
                    form.userId = $userId;
                    form.id = vm.dataDictionary.id;
                    vm.dataDictionary.id == null ? form.operationType = 'add' : form.operationType = 'edit';

                    let request = {
                        url: 'dictionary/addDataDictionary',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();


                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });
        });


    const vm = new Vue({
        el: "#app",
        data: {
            dataDictionary: {
                id: null,
                title: null,
                label: null,
                type: null,
                dataValue: null,
                dataRemark: null,
                serialNumber: null
            }
        },
        created() {
            if (recordId) {
                let request = {
                    url: 'dictionary/findDataDictionaryInfo',
                    data: {
                        userId: $userId,
                        recordId: recordId
                    },
                    method: "POST"
                };
                sendRequest(request, (res) => {
                    // console.log(res);
                    this.dataDictionary = res.data;
                })

            }
        },
        methods: {},


    });
    setTimeout(() => {
        //修改状态
        let form = layui.form;
        //查字典类型
        let request = {
            url: 'dictionary/findDataDictionaryTypeSelect/0',
            data: {
                userId: $userId,
                label: 'INVOICE_TYPE'
            },
            method: "GET",
        };
        sendRequest(request, (res) => {
            let billType = res.data;
            $.each(billType, function (index, item) {
                let opt = $("<option value=" + item.name + ">" + item.name + "</option>");
                $("select[name=type]").append(opt);

            });

            $("select[name=type]").val(vm.dataDictionary.type);

            form.render('select');
        });
    }, 300)
</script>

</body>

</html>
